package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

/**
 * @Author：无敌暴龙战士
 * @Package：org.example.config
 * @Project：learn_spring_security
 * @name：MySecurityConfig
 * @Date：2025/2/12 1:45
 * @Filename：MySecurityConfig
 * @Description: 白定义类实现用户详情服务接口
 */
@Configuration
public class MySecurityConfig {
    @Bean
    public UserDetailsService userDetailsService() {
        //创建两个用户
        UserDetails aaa = User.builder().username("aaa").password("123456").roles("student").build();
        UserDetails bbb = User.builder().username("bbb").password("123456").roles("teacher").build();

        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        manager.createUser(aaa);
        manager.createUser(bbb);
        return manager;
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }


}


